{extend name="public:base" /}

{block name="body"}
<div class="row">
    <div class="col-md-8">
        <div class="page-header">
            <h2><span style="color: #00925f;">{$art.title}</span> 的帖子详情</h2>
        </div>

        <div>
            <div>
                <h4><a href="{:url('detail',['id'=>$art.id])}">{$art.title}</a></h4>
                <p>发布者：{$art.user_id|getUserName}&nbsp;&nbsp;&nbsp;&nbsp;
                    发布时间:{$art.create_time|date='Y-m-d   h:m:s'} &nbsp;&nbsp;
                    阅读量：{$art.pv}
                </p>
                <div><span style="font-size: 18px">内容:</span><br><hr>{$art.content|getArtContent}<br><hr></div>

                <button class="btn btn-default" type="button" id="fav" user_id="{$art.user_id}" article_id="{$art.id}" \
                                      session_id="{$Think.session.user_id}"
                 >收 藏</button>  &nbsp;&nbsp;

                <button class="btn btn-warning" type="button" id="ok" user_id="{$art.user_id}" article_id="{$art.id}" \
                        session_id="{$Think.session.user_id}"
                > 点 赞</button>
            </div>
        </div>
        <br>

        {//评论显示}
        {volist name="commentList" id="comment" empty="无评论"}
        <div>
            <p>{$comment.user_id|getUserName} &nbsp;&nbsp;{$comment.create_time}</p>
            <div style="min-height: 50px">{$comment.content}</div>
        </div>
        {/volist}
        <div class="text-center" d>{$commentList|raw}</div>


        {//评论功能}
        <h4>发表评论</h4>
        <form class="form-horizontal" id="comment">
            <input type="hidden" name="article_id" value="{$art.id}">
            <input type="hidden" name="user_id" value="{$Think.session.user_id}">
            <textarea name="content" id="comment_content" cols="100" rows="4"></textarea>
            <br>
            <button type="button" class="btn btn-info" id="submit" >提交</button>
        </form>
        <p class="text-success" id="res"></p>

        {//富文本编辑器}
        <script >
            bkLib.onDomLoaded(function() {
                new nicEditor({iconsPath : '/static/js/nicEditorIcons.gif'}).panelInstance('comment_content');
            });
         </script>

        {//Ajax提交}
        <script>
            $('#submit').on('click',function () {
                $.get("{:url('insertComment')}",$('#comment').serialize(),function (data) {
                    if (data.status == 1){
                        $('#res').text(data.message)
                    }else if(data.status == -2){
                        alert(data.message)
                    }else{
                        $('#res').text(data.message)
                    }
                })
            })
        </script>

        <script>
            //收藏
            $(function () {
                $('#fav').on('click',function () {
                    //获取当前用户的ID和文章的ID  自定义属性
                    var userId = $(this).attr('user_id')
                    var artId = $(this).attr('article_id')
                    var sessionId = $(this).attr('session_id')
                    if(userId && artId){
                        $.ajax({
                            type:'get',
                            url:"{:url('index/fav')}",
                            data:{
                                user_id:userId,
                                article_id:artId,
                                session_id:sessionId,
                                time:new Date().getTime()
                            },
                            dataType:'json',
                            success:function (data) {
                                switch (data.status) {
                                    case 1:
                                        $('#fav').attr('class','btn btn-success')
                                        $('#fav').text(data.message)
                                        break
                                    case 0:
                                        $('#fav').attr('class','btn btn-default')
                                        $('#fav').text(data.message)
                                        break
                                    case -1:
                                        alert(data.message)
                                        break
                                    case -2:
                                        alert(data.message)
                                        window.location.href="{:url('index/user/login')}"
                                }
                            }
                            }
                        )
                    }
                })
            })


            //点赞
            $(function () {
                $('#ok').on('click',function () {
                    //获取当前用户的ID和文章的ID  自定义属性
                    var userId = $(this).attr('user_id')
                    var artId = $(this).attr('article_id')
                    var sessionId = $(this).attr('session_id')
                    if(userId && artId){
                        $.ajax({
                                type:'get',
                                url:"{:url('index/ok')}",
                                data:{
                                    user_id:userId,
                                    article_id:artId,
                                    session_id:sessionId,
                                    time:new Date().getTime()
                                },
                                dataType:'json',
                                success:function (data) {
                                    switch (data.status) {
                                        case 1:
                                            $('#ok').attr('class','btn btn-success')
                                            $('#ok').text(data.message)
                                            break
                                        case 0:
                                            $('#ok').attr('class','btn btn-default')
                                            $('#ok').text(data.message)
                                            break
                                        case -1:
                                        case -2:
                                            alert(data.message)
                                            break
                                        case -2:
                                            alert(data.message)
                                            window.location.href="{:url('index/user/login')}"
                                    }
                                }
                            }
                        )
                    }
                })
            })
        </script>

    </div>
    {/block}